package com.dengqi.mymodule.activity.camera;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.dengqi.mymodule.BaseActivity;
import com.dengqi.mymodule.R;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.module.imagelib.glide.ImageLoader;
import com.module.imagelib.glide.strategy.GlideStrategy;

import java.util.List;

/**
 * 第三方库
 */
public class CameraLibraryActivity extends BaseActivity {

    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cameralibrary);

        ImageLoader.getInstance().setImageLoader(new GlideStrategy(this));
        imageView = findViewById(R.id.imageView);

    }

    public void onBtn1(View view) {
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())
                .loadImageEngine(GlideEngine.createGlideEngine())
                .compress(true)
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    public void onBtn2(View view) {
    }

    public void onBtn31(View view) {
    }
    public void onBtn32(View view) {
    }
    public void onBtn33(View view) {
    }

    public void onBtn4(View view) {
    }

    public void onBtn5(View view) {
    }

    public void onBtn6(View view) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {// 图片选择结果回调
                List<LocalMedia> images = PictureSelector.obtainMultipleResult(data);
                // 例如 LocalMedia 里面返回三种path
                // 1.media.getPath(); 为原图path
                // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true
                // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true
                // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的
                String photoPaths = images.get(0).getCompressPath();
                ImageLoader.getInstance().load(photoPaths).into(imageView);

            }
        }
    }


}
